package com.black.web.app.my.myshoppingcar;

import com.black.app.domain.req.my.myshoppingcar.AppShoppingCarAddReq;
import com.black.app.domain.req.my.myshoppingcar.AppShoppingCarEditReq;
import com.black.app.domain.resp.my.myshoppingcar.UserShoppingCarResp;
import com.black.app.service.store.AppStoreShoppingCartService;
import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "app-我的购物车相关Api")
@RestController
@RequestMapping("/app/my/shoppingCar")
public class AppMyShoppingCarController extends BaseController {

    @Autowired
    private AppStoreShoppingCartService shoppingCartService;

    /**
     * 用户购物车列表
     * @param userId
     * @return
     */
    @ApiOperation(value = "用户购物车列表")
    @GetMapping(value = "/list/{user_id}")
    public R<PageInfo<UserShoppingCarResp>> myShoppingCarList(@PathVariable(value = "user_id") Integer userId) {
        PageInfo<UserShoppingCarResp> pageInfo = this.shoppingCartService.getMyShoppingCarList(userId);
        return R.ok(pageInfo);
    }

    /**
     * 购物车新增
     * @param req
     * @return
     */
    @ApiOperation(value = "购物车新增")
    @PostMapping
    public R add(@RequestBody @Valid AppShoppingCarAddReq req){
        boolean res = this.shoppingCartService.add(req);
        return super.isSuccess(res);
    }

    /**
     * 修改购物车
     * @param req
     * @return
     */
    @ApiOperation(value = "修改购物车")
    @PutMapping
    public R edit(@RequestBody @Valid AppShoppingCarEditReq req){
        boolean res = this.shoppingCartService.edit(req);
        return super.isSuccess(res);
    }

    /**
     * 购物车删除
     * @param Ids
     * @return
     */
    @ApiOperation(value = "购物车删除")
    @DeleteMapping("/{cart_ids}")
    public R remove(@PathVariable(value = "cart_ids") Integer[] Ids){
        boolean res = this.shoppingCartService.deleteById(Ids);
        return super.isSuccess(res);
    }
}
